<?php
class PublicAction extends Action{

    /**
     * 如果已经登录则转到后台首页，否则转到登录页面
     */
    public function login(){
        if(array_key_exists(C('USER_AUTH_KEY'), $_SESSION)){
            $this->redirect('pAdmin/index');
        }else{
            $this->display();
        }
    }

    public function logout(){
        if(true===array_key_exists(C('user_auth_key'), $_SESSION)) {
            session_destroy();
            $this->assign('msg',L('exit_success'));
        }
        $this->display('login');
    }

    /**
     * 登录验证成功则转到后台首页，否则转到登录页面并显示错误消息
     */
    public function checkLogin(){
        $userDao=new UserModel();
        if(false === $userDao->doLogin()){
            $this->assign('msg',$userDao->getError());
            $this->display('login');
        }else{
            if(array_key_exists('remind', $_POST) && false === array_key_exists('account',$_COOKIE) ){
                //两周内有效
                Cookie::set('account','admin',1209600);
            }
            $this->redirect('pAdmin/index');
        }
    }

    public function popedom(){
        if(array_key_exists(C('USER_AUTH_KEY'), $_SESSION)){
            $this->display('popedom');
        }else{
            $this->display('login');
        }
    }

    /**
     * post a comment
     *
     * @param @string default 'post'
     * @param @string id , eg:post-id
     * @param @string comment_reply_id
     * @param @string comment
     * @param @string author
     * @param @string email
     * @param @string url
     */
    public function postComment(){

    }

    public function test(){
        dump(__ROOT__);
    }

}